<template>
    <div class="container scopClass">
        <h3>分包管理</h3>
      <h3 v-show="$store.state.zangw=='1'">འགན་གཙང་ཁག་བགོས་ཀྱི་དོ་དམ་ </h3>
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <!-- <el-tab-pane label="生产分包ཐོན་སྐྱེད་འགན་བགོས་ " name="生产分包"> -->
                <el-tab-pane label="生产分包" name="生产分包">
                <el-row style="margin:20px 0;">
                    <el-col :span="7">
                        <el-input style="border-radius: 0 5px 5px 0;width:300px;" placeholder="请输入关键词"  v-model="searchName1">
                            <i slot="prefix" class="el-input__icon el-icon-search"></i>
                            <el-button slot="append" @click="handleSearch1" style="background-color: #1BC46D;color: #fff;">搜索</el-button>
                        </el-input>
                    </el-col>
                    <!-- <el-button type="primary"  style="float:right; margin-right: 10px">新增地块</el-button> -->
                </el-row>
                <el-table
                    :data="tableData"
                    border
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                    :header-cell-style="{ background:'rgba(64, 158, 255, 0.05)'}"
                >
                    <!-- <el-table-column prop="productName" sortable label="产品名称ཐོན་རྫས་ཀྱི་མིང་ "></el-table-column>
                    <el-table-column prop="batch" sortable label="加工批号ལས་སྣོན་ཆོག་མཆན་ཨང་གྲངས་ "></el-table-column>
                    <el-table-column prop="grade" sortable label="品级རིམ་པ་ "></el-table-column>
                    <el-table-column prop="totalNumber" sortable label="成品总量གྲུབ་རྫས་ཀྱི་བསྡོམས་འབོར་ "> -->
                          <el-table-column prop="productName" sortable label="产品名称 "></el-table-column>
                    <el-table-column prop="batch" sortable label="加工批号"></el-table-column>
                    <el-table-column prop="grade" sortable label="品级"></el-table-column>
                    <el-table-column prop="totalNumber" sortable label="成品总量">
						<template slot-scope="scope">
							{{scope.row.totalNumber}}{{scope.row.units}}
						</template>

					</el-table-column>
					<!-- <el-table-column prop="surplusNumber" sortable label="成品剩余量གྲུབ་རྫས་ལྷག་མའི་ཚད་ "> -->
                        <el-table-column prop="surplusNumber" sortable label="成品剩余量">
						<template slot-scope="scope">
							{{scope.row.surplusNumber}}{{scope.row.units}}
						</template>

					</el-table-column>
                    <el-table-column label="操作" width="150" align="center">
                        <template slot-scope="scope">
                            <template v-if="!added">
                            <!-- <el-button
                                type="text"
								v-if="scope.row.surplusNumber != 0"
                                @click="handleSubpackage(scope.$index, scope.row)"
                            >分包ཁག་བགོས་འགན་གཙང་ལེན་ </el-button>
                            </template>
                            <el-button
                                v-if="!check"
                                type="text"
                                @click="handleView(scope.$index, scope.row)"
                            >查看ལྟ་ཞིབ་ </el-button> -->
                               <el-button
                                type="text"
								v-if="scope.row.surplusNumber != 0"
                                @click="handleSubpackage(scope.$index, scope.row)"
                            >分包 </el-button>
                            </template>
                            <el-button
                                v-if="!check"
                                type="text"
                                @click="handleView(scope.$index, scope.row)"
                            >查看</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination layout="total, prev, pager, next, jumper" :page-size="pagesize1" @current-change="handleCurrentChange1" :total="total1" :current-page.sync="currentPage1" style="margin-top:20px"></el-pagination>
            </el-tab-pane>
            <!-- <el-tab-pane label="采购分包" name="采购分包">
                <el-row style="margin:20px 0;">
                    <el-col :span="7">
                        <el-input style="border-radius: 0 5px 5px 0;width:300px;" placeholder="请输入关键词"  v-model="searchName2">
                            <i slot="prefix" class="el-input__icon el-icon-search"></i>
                            <el-button slot="append" @click="handleSearch2">搜索</el-button>
                        </el-input>
                    </el-col>
                </el-row>
                <el-table
                    :data="tableData1"
                    border
                    ref="multipleTable"
                    header-cell-class-name="table-header">
                   <el-table-column prop="productName" sortable label="产品名称"></el-table-column>
                   <el-table-column prop="storageBatch" sortable label="入库批号"></el-table-column>
                   <el-table-column prop="supplierName" sortable label="供货商"></el-table-column>
                   <el-table-column prop="sum" sortable label="成品数量">
					   <template slot-scope="scope">
						   {{scope.row.sum}}{{scope.row.units}}
					   </template>
				   </el-table-column>
                   <el-table-column prop="subtotal" sortable label="待分包数量">
					   <template slot-scope="scope">
						   {{scope.row.subtotal}}{{scope.row.units}}
					   </template>
				   </el-table-column>
                   <el-table-column label="操作" width="150" align="center">
                       <template slot-scope="scope">
                            <template v-if="!added">
                           <el-button
                               type="text"
							   v-if="scope.row.surplusNumber != 0"
                               @click="handleSubpackage(scope.$index, scope.row)"
                           >分包</el-button>
                            </template>
                           <el-button
                               v-if="!check"
                               type="text"
                               @click="handleView(scope.$index, scope.row)"
                           >查看</el-button>
                       </template>
                   </el-table-column>
                </el-table>
                <el-pagination layout="total, prev, pager, next, jumper" :page-size="pagesize2" @current-change="handleCurrentChange2" :total="total2" :current-page.sync="currentPage2" style="margin-top:20px"></el-pagination>
            </el-tab-pane> -->


        </el-tabs>
    </div>
</template>

<script>
	import {process_findByList,storageManage_findByList} from "@/request/api"
    export default {
        data() {
            return {
                activeName: '生产分包',
                materialType: '中药材',
                searchName1: '',
                searchName2: '',
                tableData: [],
                total1: 0,
                currentPage1:1,
                pagesize1:10,
                total2: 0,
                currentPage2:1,
                pagesize2:10,
                pagesize4:10,
                listUrl: '',
                action: '',
                added:true,
                check:true,
				tableData1:[]
            };
        },
        created(){

        },
        mounted(){
           this.init1();
           this.init2();
           this.judgmentAuthority();
        },
        destroyed: function () {

        },
        methods: {
            // 调用接口
			init1(){
				let data = {
					page:this.currentPage1,
					productName:this.searchName1
				}
				process_findByList(data).then((res)=>{
					this.tableData = res.rows
					this.total1 = res.total
				})
			},
			init2() {
			    var params = {
			        page:this.currentPage2,
			        productName:this.searchName2,
					source:'采购入库'
			    }
			    storageManage_findByList(params).then((res=> {
			        this.tableData1 = res.rows;
			        this.total2 = res.total;
					for(var i=0;i<this.tableData1.length;i++){
						this.tableData1[i].sum = this.tableData1[i].specs*this.tableData1[i].number
						var st = this.tableData1[i].unit.substr(this.tableData1[i].unit.lastIndexOf('/', this.tableData1[i].unit.lastIndexOf('/') - 1) + 1);
						var str = st.lastIndexOf("\/")
						this.tableData1[i].units = st.substring(0,str)
					}
					// for(var i=0;i<this.tableData.length;i++){
					// 	this.tableData[i].num = this.tableData[i].number*this.tableData[i].specs
					// 	var st = this.tableData[i].unit.substr(this.tableData[i].unit.lastIndexOf('/', this.tableData[i].unit.lastIndexOf('/') - 1) + 1);
					// 	var str = st.lastIndexOf("\/")
					// 	this.tableData[i].units = st.substring(0,str)
					// }
			    }))
			},
            // tabs
            handleClick(tab, event) {
				this.activeName = tab.label
            },
            //跳转到分包
            handleSubpackage(index,row){
				row.source = this.activeName
				this.$router.push({
					path:'subcontract/added',
					query:{
						content:row,
						type:this.activeName
					}
				})
            },
            // 查看
            handleView(index,row){
                row.source = this.activeName
                this.$router.push({
                	path:'subcontract/check',
                	query:row
                })
            },


            // 列表搜索
            handleSearch1() {
                this.currentPage1 = 1
                this.init1()
            },
            handleSearch2() {
                this.currentPage2 = 1
                this.init2()
            },




            // 分页事件
            handleCurrentChange1(val){
                this.currentPage1 = val
                this.init1()
            },
            handleCurrentChange2(val){
                this.currentPage2 = val
                this.init2()
            },
            //判定操作按钮显示
            judgmentAuthority(){
                var type = JSON.parse(localStorage.getItem("panduanzhuangtai"))
                type.map(item1 => {
                    if(item1.name == '分包管理' && item1.children != null){
                        for(var i = 0; i < item1.children.length; i++){
                            if(item1.children[i].name == '分包') this.added = false;
                            if(item1.children[i].name == '查看') this.check = false;
                        }
                    }
                })
            }


        }
    }
</script>

<style lang="less" scoped>
// 深度作用器
/deep/.upload-daoru{
    .el-upload{
        border: none;
        width: auto;
        height: auto;
        border-radius: 0;
        float: right;
        margin-right: 10px
    }
}
.el-col{
    margin-bottom: 0;
}
/* .scopClass .el-table{ margin-top: 20px;} */
 .el-pagination{
    text-align: center;
}
/*
.el-select .el-input {
width: 130px;
}
.input-with-select .el-input-group__prepend {
background-color: #fff;
}
.el-input--small .el-input__inner{
    border-radius: 5px 0 0 5px !important;
    border-right: none;
} */
</style>
